/ / @ v e r s i o n = 5 
 
 i n d i c a t o r ( t i t l e = " n e w   R e l a t i v e   S t r e n g t h   I n d e x " ,   s h o r t t i t l e = " N E W   R S I " ,   f o r m a t = f o r m a t . p r i c e ,   p r e c i s i o n = 2 ,   t i m e f r a m e = " " ,   t i m e f r a m e _ g a p s = t r u e ) 
 
 
 
 
 
 / / / / / / F G H t r a d i n g / / / / / / 
 
 
 
 m a ( s o u r c e ,   l e n g t h ,   t y p e )   = > 
 
         s w i t c h   t y p e 
 
                 " S M A "   = >   t a . s m a ( s o u r c e ,   l e n g t h ) 
 
                 " B o l l i n g e r   B a n d s "   = >   t a . s m a ( s o u r c e ,   l e n g t h ) 
 
                 " E M A "   = >   t a . e m a ( s o u r c e ,   l e n g t h ) 
 
                 " S M M A   ( R M A ) "   = >   t a . r m a ( s o u r c e ,   l e n g t h ) 
 
                 " W M A "   = >   t a . w m a ( s o u r c e ,   l e n g t h ) 
 
                 " V W M A "   = >   t a . v w m a ( s o u r c e ,   l e n g t h ) 
 
 
 
 r s i L e n g t h I n p u t   =   i n p u t . i n t ( 1 4 ,   m i n v a l = 1 ,   t i t l e = " R S I   L e n g t h " ,   g r o u p = " R S I   S e t t i n g s " ) 
 
 r s i S o u r c e I n p u t   =   i n p u t . s o u r c e ( c l o s e ,   " S o u r c e " ,   g r o u p = " R S I   S e t t i n g s " ) 
 
 m a T y p e I n p u t   =   i n p u t . s t r i n g ( " S M A " ,   t i t l e = " M A   T y p e " ,   o p t i o n s = [ " S M A " ,   " B o l l i n g e r   B a n d s " ,   " E M A " ,   " S M M A   ( R M A ) " ,   " W M A " ,   " V W M A " ] ,   g r o u p = " M A   S e t t i n g s " ) 
 
 m a L e n g t h I n p u t   =   i n p u t . i n t ( 1 4 ,   t i t l e = " M A   L e n g t h " ,   g r o u p = " M A   S e t t i n g s " ) 
 
 b b M u l t I n p u t   =   i n p u t . f l o a t ( 2 . 0 ,   m i n v a l = 0 . 0 0 1 ,   m a x v a l = 5 0 ,   t i t l e = " B B   S t d D e v " ,   g r o u p = " M A   S e t t i n g s " ) 
 
 
 
 u p   =   t a . r m a ( m a t h . m a x ( t a . c h a n g e ( r s i S o u r c e I n p u t ) ,   0 ) ,   r s i L e n g t h I n p u t ) 
 
 d o w n   =   t a . r m a ( - m a t h . m i n ( t a . c h a n g e ( r s i S o u r c e I n p u t ) ,   0 ) ,   r s i L e n g t h I n p u t ) 
 
 r s i   =   d o w n   = =   0   ?   1 0 0   :   u p   = =   0   ?   0   :   1 0 0   -   ( 1 0 0   /   ( 1   +   u p   /   d o w n ) )   
 
 r s i M A   =   m a ( r s i ,   m a L e n g t h I n p u t ,   m a T y p e I n p u t ) 
 
 i s B B   =   m a T y p e I n p u t   = =   " B o l l i n g e r   B a n d s " 
 
 
 
 p l o t ( r s i ,   " R S I " ,   c o l o r = # 7 E 5 7 C 2 , d i s p l a y = d i s p l a y . n o n e ) 
 
 p l o t ( r s i M A ,   " R S I - b a s e d   M A " ,   c o l o r = c o l o r . y e l l o w , d i s p l a y = d i s p l a y . n o n e ) 
 
 r s i U p p e r B a n d   =   h l i n e ( 7 0 ,   " R S I   U p p e r   B a n d " ,   c o l o r = # 7 8 7 B 8 6 ) 
 
 h l i n e ( 5 0 ,   " R S I   M i d d l e   B a n d " ,   c o l o r = c o l o r . n e w ( # 7 8 7 B 8 6 ,   5 0 ) ) 
 
 r s i L o w e r B a n d   =   h l i n e ( 3 0 ,   " R S I   L o w e r   B a n d " ,   c o l o r = # 7 8 7 B 8 6 ) 
 
 f i l l ( r s i U p p e r B a n d ,   r s i L o w e r B a n d ,   c o l o r = c o l o r . r g b ( 1 2 6 ,   8 7 ,   1 9 4 ,   9 0 ) ,   t i t l e = " R S I   B a c k g r o u n d   F i l l " ) 
 
 b b U p p e r B a n d   =   p l o t ( i s B B   ?   r s i M A   +   t a . s t d e v ( r s i ,   m a L e n g t h I n p u t )   *   b b M u l t I n p u t   :   n a ,   t i t l e   =   " U p p e r   B o l l i n g e r   B a n d " ,   c o l o r = c o l o r . g r e e n ) 
 
 b b L o w e r B a n d   =   p l o t ( i s B B   ?   r s i M A   -   t a . s t d e v ( r s i ,   m a L e n g t h I n p u t )   *   b b M u l t I n p u t   :   n a ,   t i t l e   =   " L o w e r   B o l l i n g e r   B a n d " ,   c o l o r = c o l o r . g r e e n ) 
 
 
 
 x = i n p u t ( d e f v a l   =   3 6 ) 
 
 
 
 r s i n e w = t a . l i n r e g ( r s i , x , 0 ) 
 
 r s i M A n e w = t a . l i n r e g ( r s i M A , x , 0 ) 
 
 
 
 p l o t ( r s i n e w ,   " N E W   R S I " ,   c o l o r = # 7 E 5 7 C 2 ) 
 
 p l o t ( r s i M A n e w ,   " N E W   R S I - b a s e d   M A " ,   c o l o r = c o l o r . y e l l o w ) 
 
 